// 整体路由 npm install react-router-dom

import React from 'react'
import { HashRouter,Route,Switch,Redirect } from 'react-router-dom'//用HashRouter,方便打包
import Login from '../views/login/Login'
import NewsSandBox from '../views/sandBox/NewsSandBox'
export default function IndexRouter() {
    return (
        <HashRouter>
          {/* 精准匹配route */}
            <Switch>
                <Route path="/login" component={Login} />
                {/* 如果输入不是/login,就重定向 */}
                <Route path="/" render={()=>  
                  // 路由拦截
                  //如果有token,说明登录过，那么跳到主板页面；如果没有token,说明没登陆过，就要跳到登录页
                    localStorage.getItem("token")?<NewsSandBox/>:<Redirect to='/login'/>
                } />
            </Switch>
            
        </HashRouter>
    )
}
